package com.shop2cn.iapi.sqoptrade.parameter.model.placeorder;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import com.shop2cn.iapi.sqoptrade.parameter.utill.Utils;
import com.shop2cn.iapi.sqoptrade.parameter.vo.CatalogApportionVo;
import com.shop2cn.iapi.sqoptrade.parameter.vo.OrderItemVo;
import com.shop2cn.iapi.sqoptrade.parameter.vo.SellerPromotionVo;
import com.ymttest.database.sharding.db.sharding.model.ShenqiProxyChainPo;

/**
 */
public class OrderItem {

	// 订单项ID
	private long orderItemId;
	// 订单ID
	private long orderId;
	// 该订单项分摊到的平台优惠券面值
	private BigDecimal ymatouCouponValue = BigDecimal.ZERO;
	// 该订单项分摊到的商家优惠券面值
	private BigDecimal sellerCouponValue = BigDecimal.ZERO;
	// 分摊的商家优惠金额
	private BigDecimal sellerPromotionAmount = BigDecimal.ZERO;
	// 该订单项分摊到的返点金额
	private BigDecimal rebateAmountValue = BigDecimal.ZERO;
	
	// 分摊的区域折扣金额
	private BigDecimal regionDiscountValue = BigDecimal.ZERO;
	
	// 享受的商家优惠
	private SellerPromotionVo sellerPromotion;
	
	// 店主的毛利润
	private BigDecimal orderItemGrossProfit;
	
	// 分配到该商品项的规格优惠
	private List<CatalogApportionVo> catalogApportionVos = new ArrayList<CatalogApportionVo>();
	
	// 分摊的商家折扣金额
	private BigDecimal discount = BigDecimal.ZERO;
	
	// 分摊的积分抵扣金额
	private BigDecimal integralDeduction = BigDecimal.ZERO;

	// 分摊的积分
	private Long integral = 0L;
	
	private BigDecimal taxFee;

	private OrderItemVo itemVo;
	
	// 商品的服务费率
	private BigDecimal serviceRate;
	
	private List<ShenqiProxyChainPo> shenqiProxyChain;

	// 已经分摊的商家优惠的数量
	public int countPromotionProductNum() {
		int count = 0;
		for (CatalogApportionVo v : catalogApportionVos) {
			count += v.getCount();
		}
		return count;
	}

	/**
	 * 订单项剩余最大可优惠金额
	 *
	 * @return
	 */
	public BigDecimal calcMaxPromotionLeft() {
		BigDecimal result = getItemVo().getProductPrice()
				.multiply(new BigDecimal(getItemVo().getProductNum()))
				.subtract(new BigDecimal("0.01"))
				.subtract(Utils.zeroIfNull(ymatouCouponValue))
				.subtract(Utils.zeroIfNull(sellerCouponValue))
				.subtract(Utils.zeroIfNull(sellerPromotionAmount));
		if (result.compareTo(BigDecimal.ZERO) < 0) {
			return BigDecimal.ZERO;
		}
		return result;
	}

	public long getOrderItemId() {
		return orderItemId;
	}

	public void setOrderItemId(long orderItemId) {
		this.orderItemId = orderItemId;
	}

	public long getOrderId() {
		return orderId;
	}

	public void setOrderId(long orderId) {
		this.orderId = orderId;
	}

	public BigDecimal getYmatouCouponValue() {
		return ymatouCouponValue;
	}

	public void setYmatouCouponValue(BigDecimal ymatouCouponValue) {
		this.ymatouCouponValue = ymatouCouponValue;
	}

	public BigDecimal getSellerCouponValue() {
		return sellerCouponValue;
	}

	public void setSellerCouponValue(BigDecimal sellerCouponValue) {
		this.sellerCouponValue = sellerCouponValue;
	}

	public BigDecimal getSellerPromotionAmount() {
		return sellerPromotionAmount;
	}

	public void setSellerPromotionAmount(BigDecimal sellerPromotionAmount) {
		this.sellerPromotionAmount = sellerPromotionAmount;
	}

	public SellerPromotionVo getSellerPromotion() {
		return sellerPromotion;
	}

	public void setSellerPromotion(SellerPromotionVo sellerPromotion) {
		this.sellerPromotion = sellerPromotion;
	}

	public List<CatalogApportionVo> getCatalogApportionVos() {
		return catalogApportionVos;
	}

	public void setCatalogApportionVos(
			List<CatalogApportionVo> catalogApportionVos) {
		this.catalogApportionVos = catalogApportionVos;
	}

	public OrderItemVo getItemVo() {
		return itemVo;
	}

	public void setItemVo(OrderItemVo itemVo) {
		this.itemVo = itemVo;
	}

	public BigDecimal getDiscount() {
		return discount;
	}

	public void setDiscount(BigDecimal discount) {
		this.discount = discount;
	}

	public BigDecimal getRebateAmountValue() {
		return rebateAmountValue;
	}

	public void setRebateAmountValue(BigDecimal rebateAmountValue) {
		this.rebateAmountValue = rebateAmountValue;
	}

	public BigDecimal getServiceRate() {
		return serviceRate;
	}

	public void setServiceRate(BigDecimal serviceRate) {
		this.serviceRate = serviceRate;
	}

	public BigDecimal getIntegralDeduction() {
		return integralDeduction;
	}

	public void setIntegralDeduction(BigDecimal integralDeduction) {
		this.integralDeduction = integralDeduction;
	}

	public Long getIntegral() {
		return integral;
	}

	public void setIntegral(Long integral) {
		this.integral = integral;
	}

	public BigDecimal getOrderItemGrossProfit() {
		return orderItemGrossProfit;
	}

	public void setOrderItemGrossProfit(BigDecimal orderItemGrossProfit) {
		this.orderItemGrossProfit = orderItemGrossProfit;
	}

	public BigDecimal getTaxFee() {
		return taxFee;
	}

	public void setTaxFee(BigDecimal taxFee) {
		this.taxFee = taxFee;
	}

	public BigDecimal getRegionDiscountValue() {
		return regionDiscountValue;
	}

	public void setRegionDiscountValue(BigDecimal regionDiscountValue) {
		this.regionDiscountValue = regionDiscountValue;
	}

	public List<ShenqiProxyChainPo> getShenqiProxyChain() {
		return shenqiProxyChain;
	}

	public void setShenqiProxyChain(List<ShenqiProxyChainPo> shenqiProxyChain) {
		this.shenqiProxyChain = shenqiProxyChain;
	}

	public BigDecimal getProductPrice() {

		OrderItemVo itemVo = this.getItemVo();

		return itemVo.getProductPrice()
				.multiply(new BigDecimal(itemVo.getProductNum()));
	}
}
